package cn.itcast.servlet;

import cn.itcast.domain.Student;
import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class Demo_C3p0 {
    public static void main(String[] args) throws Exception {
        List<Student> lis = new ArrayList<Student>();
        //创建连接池对象
        ComboPooledDataSource cd = new ComboPooledDataSource();
        //数据库的四大基本特征
        cd.setDriverClass("com.mysql.jdbc.Driver");
        cd.setJdbcUrl("jdbc:mysql://192.168.247.123/db14");
        cd.setUser("root");
        cd.setPassword("root");

        //获取连接
        Connection conn = cd.getConnection();
        String sql = "select * from student";
        PreparedStatement ps = conn.prepareStatement(sql);

        ResultSet rs = ps.executeQuery();

        while (rs.next()){
            Student stu = new Student(rs.getInt(1),rs.getString(2),rs.getInt(3),rs.getDate(4));
            lis.add(stu);
        }
        conn.close();
        ps.close();
        rs.close();
        System.out.println(lis);
    }
}
